package com.dushiguang.findhoney.Utils.Http;

import android.util.Log;

import com.dushiguang.findhoney.Utils.AnalysisJson.AnalysisJson;

/**
 * Created by ex-dushiguang201 on 2015-11-19.
 */
public class ApiInit {

    public static <T> T getBean(String url, Class<T> entityClass) {
        T entity = null;
        String jsonStr = "";
        jsonStr = getMethod(url);

        entity = AnalysisJson.getEntity(jsonStr,entityClass );
        return entity;
    }

    public static String getMethod(String url) {
        String ret = null;
        HttpRequest request = HttpRequest.get(url);
        Log.e("dushiguang", "request.ok()" + request.ok());
        try {
            if (request.ok()) {
                ret = request.body();
                Log.e("dushiguang","ret=====>>>>" + ret );
            }
        } catch (HttpRequest.HttpRequestException exception) {
            exception.printStackTrace();
            ret = null;
        }
        return ret;
    }

    /**
     * 从本地文件中得到Json进行解析
     * @param entityClass
     * @param <T>
     * @return
     */
    public static <T> T getLocalBean(String jsonStr, Class<T> entityClass) {
        T entity = null;
        entity = AnalysisJson.getEntity(jsonStr,entityClass );
        return entity;
    }

}
